package com.prs.crm.action.assets;

import java.math.BigDecimal;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.ws.rs.core.Request;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;


import com.prs.crm.context.AppContext;
import com.prs.crm.domain.approval.Application;
import com.prs.crm.domain.assets.AssetsBigClass;
import com.prs.crm.domain.assets.AssetsDetail;
import com.prs.crm.domain.assets.AssetsLingYong;
import com.prs.crm.domain.assets.AssetsRegister;
import com.prs.crm.domain.assets.AssetsSmallClass;
import com.prs.crm.service.ReportService;
import com.prs.crm.service.approval.ApplicationService;
import com.prs.crm.service.assets.AssetsBigClassService;
import com.prs.crm.service.assets.AssetsDetailService;
import com.prs.crm.service.assets.AssetsLingYongService;
import com.prs.crm.service.assets.AssetsRegisterService;
import com.prs.crm.service.assets.AssetsSmallClassService;

public class AssetsRegisterAction extends BaseAction{
	private PaginationSupport pagination;
	private Integer[] ids;
	private AssetsRegisterService assetsRegisterService;
	private AssetsRegister assetsRegister = null;           
	private List<AssetsBigClass> bigClass;
	private AssetsBigClass assetsBigClass;
	private AssetsBigClassService assetsBigClassService;
	private AssetsSmallClassService assetsSmallClassService;
	private Integer bigid;
	private Integer bigids;
	private List<AssetsSmallClass> smallClass;
	private AssetsDetail assetsDetail;
	private AssetsDetailService assetsDetailService;
	private String rec;   //控制明细
	private String num;   //资产编号
	private Integer userId; //归还人id
	private List<AssetsRegister> registers;
	private Application application;
	private ApplicationService ApplicationService;
	
	private AssetsLingYong assetsLingYong;
	private AssetsLingYongService assetsLingYongService;
	
	private List<AssetsLingYong> assetsly;
	private Boolean isZJ;
	
	private AssetsBigClass big;
	public Integer getBigids() {
		return bigids;
	}
	public void setBigids(Integer bigids) {
		this.bigids = bigids;
	}
	public AssetsBigClass getBig() {
		return big;
	}
	public void setBig(AssetsBigClass big) {
		this.big = big;
	}
	public Boolean getIsZJ() {
		return isZJ;
	}
	public void setIsZJ(Boolean isZJ) {
		this.isZJ = isZJ;
	}
	public Application getApplication() {
		return application;
	}
	public void setApplication(Application application) {
		this.application = application;
	}
	public ApplicationService getApplicationService() {
		return ApplicationService;
	}
	public void setApplicationService(ApplicationService applicationService) {
		ApplicationService = applicationService;
	}
	public List<AssetsLingYong> getAssetsly() {
		return assetsly;
	}
	public void setAssetsly(List<AssetsLingYong> assetsly) {
		this.assetsly = assetsly;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public AssetsRegisterService getAssetsRegisterService() {
		return assetsRegisterService;
	}
	public void setAssetsRegisterService(AssetsRegisterService assetsRegisterService) {
		this.assetsRegisterService = assetsRegisterService;
	}
	public AssetsRegister getAssetsRegister() {
		return assetsRegister;
	}
	public void setAssetsRegister(AssetsRegister assetsRegister) {
		this.assetsRegister = assetsRegister;
	}
	public List<AssetsBigClass> getBigClass() {
		return bigClass;
	}
	public void setBigClass(List<AssetsBigClass> bigClass) {
		this.bigClass = bigClass;
	}
	public AssetsBigClassService getAssetsBigClassService() {
		return assetsBigClassService;
	}
	public void setAssetsBigClassService(AssetsBigClassService assetsBigClassService) {
		this.assetsBigClassService = assetsBigClassService;
	}
	public AssetsSmallClassService getAssetsSmallClassService() {
		return assetsSmallClassService;
	}
	public void setAssetsSmallClassService(
			AssetsSmallClassService assetsSmallClassService) {
		this.assetsSmallClassService = assetsSmallClassService;
	}
	public Integer getBigid() {
		return bigid;
	}
	public void setBigid(Integer bigid) {
		this.bigid = bigid;
	}
	public List<AssetsSmallClass> getSmallClass() {
		return smallClass;
	}
	public void setSmallClass(List<AssetsSmallClass> smallClass) {
		this.smallClass = smallClass;
	}
	public AssetsBigClass getAssetsBigClass() {
		return assetsBigClass;
	}
	public void setAssetsBigClass(AssetsBigClass assetsBigClass) {
		this.assetsBigClass = assetsBigClass;
	}
	public AssetsDetail getAssetsDetail() {
		return assetsDetail;
	}
	public void setAssetsDetail(AssetsDetail assetsDetail) {
		this.assetsDetail = assetsDetail;
	}
	public AssetsDetailService getAssetsDetailService() {
		return assetsDetailService;
	}
	public void setAssetsDetailService(AssetsDetailService assetsDetailService) {
		this.assetsDetailService = assetsDetailService;
	}
	public String getRec() {
		return rec;
	}
	public void setRec(String rec) {
		this.rec = rec;
	}
	public String getNum() {
		return num;
	}
	public void setNum(String num) {
		this.num = num;
	}
	public List<AssetsRegister> getRegisters() {
		return registers;
	}
	public void setRegisters(List<AssetsRegister> registers) {
		this.registers = registers;
	}
	public Integer getUserId() {
		return userId;
	}
	public void setUserId(Integer userId) {
		this.userId = userId;
	}
	public AssetsLingYong getAssetsLingYong() {
		return assetsLingYong;
	}
	public void setAssetsLingYong(AssetsLingYong assetsLingYong) {
		this.assetsLingYong = assetsLingYong;
	}
	public AssetsLingYongService getAssetsLingYongService() {
		return assetsLingYongService;
	}
	public void setAssetsLingYongService(AssetsLingYongService assetsLingYongService) {
		this.assetsLingYongService = assetsLingYongService;
	}
	///////////////////////////////////////////////////////////////////////////////////
	//报废单查询
	@Action("listselectScrap")
	public String listselectScrap(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(AssetsRegister.class)
		.add(Restrictions.ne("state", "已报废"));
		this.setPagination(this.assetsRegisterService.listByPage(criteria, 
				this.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}
	//归还查询结果
	@Action("listselectRevert")
	public String listselectRevert(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(AssetsRegister.class)
		.createAlias("assetsLingYong", "ly").add(Restrictions.isNull("asssteRevert.id"))
		.add(Restrictions.eq("state", "领用")).add(Restrictions.eq("ly.person.id", userId));
		this.setPagination(this.assetsRegisterService.listByPage(criteria, 
				this.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}
	//领用按钮查询结果
	@Action("listselect")
	public String listselect(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(AssetsRegister.class)
									.add(Restrictions.eq("state", "在库")).add(Restrictions.isNull("assetsLingYong.id"));
		criteria.add(Restrictions.eq("state", "已归还"));
		this.setPagination(this.assetsRegisterService.listByPage(criteria, 
				this.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}
	@Action("listAssetsRegister")
	public String listAssetsRegister(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(AssetsRegister.class);
		this.setPagination(this.assetsRegisterService.listByPage(criteria, 
				this.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}
	@Action("editAssetsRegister")
	public String editAssetsRegister(){
		if(assetsRegister == null){
			rec = "";
		}
		this.bigClass = this.assetsBigClassService.getAll();
//		this.smallClass = this.assetsSmallClassService.getAll();
		return SUCCESS;
	}
	//保存
	@Action(value="saveAssetsRegister",results={
			@Result(name="success",type="redirect",location="listAssetsRegister"),
			@Result(name="error",type="chain",location="editAssetsRegister")})
	public String saveAssetsRegister(){		
		Set<AssetsDetail> detail = null;
		if(mc != null){
			detail = new HashSet<AssetsDetail>();
			for(int i=0;i<mc.length;i++){
				this.assetsDetail = new AssetsDetail();
				if(did != null){
					assetsDetail.setId(did[i]);
				}
				assetsDetail.setName(mc[i]);
				assetsDetail.setGuige(gg[i]);
				assetsDetail.setUnits(dw[i]);
				assetsDetail.setNumber(sl[i]);
				assetsDetail.setRemark(bz[i]);
				assetsDetail.setAssetsRegister(assetsRegister);
				this.assetsDetailService.save(assetsDetail);
				detail.add(assetsDetail);
			}
		}
		assetsRegister.setAssetsDetails(detail);
		this.assetsRegisterService.save(assetsRegister);
//		application = new Application();
//		application.setType("一般");
//		application.setAppName("[一般]"+"历史资产登记");
//		application.setSqType(2);
//		application.setSpr(0);
//		application.setPerson(assetsRegister.getRecorder());
//		application.setResign("资产登记");
//		application.setAssetsRegister(assetsRegister);
//		this.getApplicationService().save(application);
		return SUCCESS;
	}
	//保存并继续
	@Action(value="saveedAssetsRegister",results={
			@Result(name="success",type="redirect",location="editAssetsRegister"),
			@Result(name="error",type="chain",location="editAssetsRegister")})
	public String saveedAssetsRegister(){	
		List<AssetsRegister> as=this.getAssetsRegisterService().getAll();
		int n=0;
		int b=0;
		for (AssetsRegister ar : as) {
			if (ar.getName().equals(assetsRegister.getName())) {
				n++;
			}
			if (ar.getNum().equals(assetsRegister.getNum())) {
				b++;
			}
		}
		if (n>0) {
			addActionError("资产名称已经存在,请重新输入");
			return ERROR;
		}
		if (b>0) {
			addActionError("资产编号已经存在,请重新输入");
			return ERROR;
		}
		Set<AssetsDetail> detail = null;
		if(mc != null){
			detail = new HashSet<AssetsDetail>();
			for(int i=0;i<mc.length;i++){
				this.assetsDetail = new AssetsDetail();
				if(did != null){
					assetsDetail.setId(did[i]);
				}
				assetsDetail.setName(mc[i]);
				assetsDetail.setGuige(gg[i]);
				assetsDetail.setUnits(dw[i]);
				assetsDetail.setNumber(sl[i]);
				assetsDetail.setRemark(bz[i]);
				this.assetsDetailService.save(assetsDetail);
				detail.add(assetsDetail);
			}
		}
		assetsRegister.setAssetsDetails(detail);
		this.assetsRegisterService.save(assetsRegister);
//		application = new Application();
//		application.setType("一般");
//		application.setAppName("[一般]"+"历史资产登记");
//		application.setSqType(2);
//		application.setSpr(0);
//		application.setPerson(assetsRegister.getRecorder());
//		application.setResign("资产登记");
//		application.setAssetsRegister(assetsRegister);
//		this.getApplicationService().save(application);
		return SUCCESS;
	}
	@Action(value="removeAssetsRegister",results={
			@Result(name="success",type="redirect",location="listAssetsRegister"),
			@Result(name="error",type="chain",location="listAssetsRegister")})
	public String removeAssetsRegister(){
		if(ids == null){
			this.setPrompt("请选择要删除的数据行！");
			return ERROR;
		}
		this.assetsRegisterService.batchRemove(ids);
		return SUCCESS;
	}
	@Action("viewAssetsRegister")
	public String viewAssetsRegister(){
		this.bigClass = this.assetsBigClassService.getAll();
		return SUCCESS;
	}
	//级联小类
	@Action(value="ajaxAssetsSmall",results = { @Result(name = "success", type = "json",
			params = {"root", "smallClass" }) })
	public String AjaxAssetsSmall(){
		smallClass = this.assetsSmallClassService.getAllSmallClassByBigId(bigids);			
		return SUCCESS; 
	}
	//当前大类信息
	@Action(value="ajaxBigByid",results = { @Result(name = "success", type = "json",
			params = {"root", "assetsBigClass" }) })
	public String ajaxBigByid(){
		assetsBigClass = this.assetsBigClassService.getBigClassByid(bigid);	
		return SUCCESS;
	}
	@Action(value="ajaxLingYong",results = { @Result(name = "success", type = "json",
			params = {"root", "assetsly" }) })
	public String ajaxLingYong(){
		assetsly=this.assetsLingYongService.getAll();
		return SUCCESS;
	}
	
	@Action(value="ajaxPersonByDept",results = { @Result(name = "success", type = "json",
			params = {"root", "assetsBigClass" }) })
	public String ajaxPersonByDept(){
		return SUCCESS;
	}
	//根据编号查询
	@Action(value="selectRegister",results = { @Result(name = "success", type = "json",
			params = {"root", "assetsRegister" }) })
	public String selectRegister(){
		this.assetsRegister = null;
		assetsRegister = this.assetsRegisterService.getByNum(num);
		return SUCCESS;
	}
	//
	@Action(value="selectCheckBox",results={
			@Result(name="success",type="redirect",location="editAssetsLingYong"),
			@Result(name="error",type="chain",location="listselect")})
	public String selectCheckBox(){
		if(ids==null){
			this.setPrompt("请选择一行数据！");
			return ERROR;
		}
		registers = this.assetsRegisterService.getAllByids(ids);
		return SUCCESS;
	} 
	/*************************************我的资产**********************************************/
	@Action("listMyAssetsRegister")
	public String listMyAssetsRegister(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(AssetsRegister.class)
		.createAlias("assetsLingYong", "ly").add(Restrictions.eq("state", "领用"))
		.add(Restrictions.eq("ly.person.id", AppContext.getAccountContext().getUser().getId()));
		this.setPagination(this.assetsRegisterService.listByPage(criteria, 
				this.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}
	
	/***********************明细数据**************************/
	private Integer[] did; //id
	private String[] mc;  //配置名称
	private String[] gg;  //规格型号
	private String[] dw;  //单位
	private String[] sl;  //数量
	private String[] bz;  //备注
	public String[] getMc() {
		return mc;
	}
	public void setMc(String[] mc) {
		this.mc = mc;
	}
	public String[] getGg() {
		return gg;
	}
	public void setGg(String[] gg) {
		this.gg = gg;
	}
	public String[] getDw() {
		return dw;
	}
	public void setDw(String[] dw) {
		this.dw = dw;
	}
	public String[] getSl() {
		return sl;
	}
	public void setSl(String[] sl) {
		this.sl = sl;
	}
	public String[] getBz() {
		return bz;
	}
	public void setBz(String[] bz) {
		this.bz = bz;
	}
	public Integer[] getDid() {
		return did;
	}
	public void setDid(Integer[] did) {
		this.did = did;
	}
	
	/***************************************yanghao******************************************/
	@Action("listAssetsHistoryRegister")
	public String listAssetsHistoryRegister(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(AssetsRegister.class).add(Restrictions.eq("state","领用"));
		this.setPagination(this.assetsRegisterService.listByPage(criteria, 
				this.getPaginationHelper().prepare(pagination)));
		return SUCCESS;
	}
	
	@Action("editAssetsHistoryRegister")
	public String editAssetsHistoryRegister(){
		if (assetsRegister==null) {
			rec="";
		}else{
			rec="7";
		}
		this.bigClass=this.assetsBigClassService.getAll();
		return SUCCESS;
	}
	
	@Action("updateAssetsHistoryRegister")
	public String updateAssetsHistoryRegister(){
		if (assetsRegister==null) {
			rec="";
		}
		this.bigClass=this.assetsBigClassService.getAll();
		return SUCCESS;
	}
	
	@Action("viewAssetsHistoryRegister")
	public String viewAssetsHistoryRegister(){
		if (assetsRegister==null) {
			rec="";
		}
		this.bigClass=this.assetsBigClassService.getAll();
		return SUCCESS;
	}


	@Action(value="saveAssetsHistoryRegister",results={
			@Result(name="success",type="redirect",location="listAssetsHistoryRegister"),
			@Result(name="error",type="chain",location="editAssetsHistoryRegister")})
	public String saveAssetsHistoryRegister(){
		List<AssetsRegister> as=this.getAssetsRegisterService().getAll();
		int n=0;
		int b=0;
		for (AssetsRegister ar : as) {
			if (ar.getName().equals(assetsRegister.getName())) {
				n++;
			}
			if (ar.getNum().equals(assetsRegister.getNum())) {
				b++;
			}
		}
		if (n>0) {
			addActionError("资产名称已经存在,请重新输入");
			return ERROR;
		}
		if (b>0) {
			addActionError("资产编号已经存在,请重新输入");
			return ERROR;
		}
		assetsLingYong.setType(2);
		int number=1000000;
		assetsLingYong.setNumber("SYS1339"+(int)(Math.random()*number));

		assetsRegister.setAssetsLingYong(assetsLingYong);	
		Set<AssetsDetail> detail = null;
		if(mc != null){
			detail = new HashSet<AssetsDetail>();
			for(int i=0;i<mc.length;i++){
				this.assetsDetail = new AssetsDetail();
				if(did != null){
					assetsDetail.setId(did[i]);
				}
				assetsDetail.setName(mc[i]);
				assetsDetail.setGuige(gg[i]);
				assetsDetail.setUnits(dw[i]);
				assetsDetail.setNumber(sl[i]);
				assetsDetail.setRemark(bz[i]);
				this.assetsDetailService.save(assetsDetail);
				detail.add(assetsDetail);
			}
		}
		assetsRegister.setAssetsDetails(detail);
		Set<AssetsRegister> assets=new HashSet<AssetsRegister>();
		
		this.assetsRegisterService.save(assetsRegister);
		assets.add(assetsRegister);
		if(assetsRegister!=null){
		if(assetsRegister.getIsZJ()==true){	
			double zjczlv=assetsRegister.getCanzhi()/100;//残值率
			double assetscz=assetsRegister.getFpje()*assetsRegister.getCanzhi()/100;//资产残值
			double fpje=assetsRegister.getFpje();//资产原值
			double zjnx=assetsRegister.getZjnx();
			int startMonth=Integer.parseInt(assetsRegister.getZjstart());
			double i=1.0;
			double a=12.0;
			double yearZjlv=(i-zjczlv)/zjnx;//年折旧率
			double monthZjlv=yearZjlv/a;//月折旧率
			double monthZj=((i-zjczlv)/(zjnx*a))*fpje;//月折旧值	
			BigDecimal big=new BigDecimal(monthZj);
			double monthzj1=big.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
			double monthcz=fpje-monthZj-assetscz;//本月残值
			BigDecimal big1=new BigDecimal(monthcz);
			double monthcz1=big1.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
			
			Date date=new Date();
			SimpleDateFormat sdf=new SimpleDateFormat("yyyyMM");
			String day=sdf.format(date);//当前年月
			int days=Integer.parseInt(day)+1;
			int monthNum=Integer.parseInt(day)-startMonth+2;
			double zjall=monthZj*monthNum;//已折旧总值
			BigDecimal big2=new BigDecimal(zjall);
			double zjall1=big2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
			double assetsjz=fpje-monthzj1*monthNum;
//			System.out.println("残值率："+zjczlv);
//			System.out.println("年："+zjnx);
//			System.out.println("资产残值："+assetscz);
//			System.out.println("年折旧率："+yearZjlv);
//			System.out.println("月折旧率："+monthZjlv);
//			System.out.println("月折旧值："+monthzj1);
//			System.out.println("残值："+monthcz1);
//			System.out.println("资产净值:"+assetsjz);
//			System.out.println("当前年月："+days);
//			System.out.println("开始年月："+startMonth);
//			System.out.println("已折旧月数"+monthNum);
//			System.out.println("折旧总值"+zjall1);
			
			assetsRegister.setOperateType("USES");
			assetsRegister.setOperatePerson("admin");
			assetsRegister.setZjnow(assetsRegister.getZjnow());
			assetsRegister.setRecordTime(assetsRegister.getRecordTime());
			assetsRegister.setZjCurrentMonth(monthzj1);
			assetsRegister.setCzMinth(monthcz1);
			assetsRegister.setZcjz(assetsjz);
			assetsRegister.setZjnow(String.valueOf(days));
			assetsRegister.setZjmonth(monthNum);
			assetsRegister.setZjAll(zjall1);
			}
		}
		assetsLingYong.setAssetsRegisters(assets);
		this.assetsLingYongService.saveLingYongAndHitory(assetsLingYong);	
		return SUCCESS;
	}
	
	@Action(value="saveAssetsHistoryRegisters",results={
			@Result(name="success",type="redirect",location="editAssetsHistoryRegister"),
			@Result(name="error",type="chain",location="editAssetsHistoryRegister")})
	public String saveAssetsHistoryRegisters(){
		this.saveAssetsHistoryRegister();	
		return SUCCESS;
	}
	@Action(value="saveUpdateAssetsHistoryRegister",results={
			@Result(name="success",type="redirect",location="listAssetsHistoryRegister"),
			@Result(name="error",type="chain",location="updateAssetsHistoryRegister")})
	public String saveUpdateAssetsHistoryRegister(){
		assetsLingYong.setType(2);
		assetsRegister.setAssetsLingYong(assetsLingYong);	
		Set<AssetsDetail> detail = null;
		if(mc != null){
			detail = new HashSet<AssetsDetail>();
			for(int i=0;i<mc.length;i++){
				this.assetsDetail = new AssetsDetail();
				if(did != null){
					assetsDetail.setId(did[i]);
				}
				assetsDetail.setName(mc[i]);
				assetsDetail.setGuige(gg[i]);
				assetsDetail.setUnits(dw[i]);
				assetsDetail.setNumber(sl[i]);
				assetsDetail.setRemark(bz[i]);
				this.assetsDetailService.save(assetsDetail);
				detail.add(assetsDetail);
			}
		}
		assetsRegister.setAssetsDetails(detail);
		Set<AssetsRegister> assets=new HashSet<AssetsRegister>();
		
		this.assetsRegisterService.save(assetsRegister);
		assets.add(assetsRegister);
		if(assetsRegister!=null){
			if(assetsRegister.getIsZJ()==true){	
				double zjczlv=assetsRegister.getCanzhi()/100;//残值率
				double assetscz=assetsRegister.getFpje()*assetsRegister.getCanzhi()/100;//资产残值
				double fpje=assetsRegister.getFpje();//资产原值
				double zjnx=assetsRegister.getZjnx();
				int startMonth=Integer.parseInt(assetsRegister.getZjstart());
				double i=1.0;
				double a=12.0;
				double yearZjlv=(i-zjczlv)/zjnx;//年折旧率
				double monthZjlv=yearZjlv/a;//月折旧率
				double monthZj=((i-zjczlv)/(zjnx*a))*fpje;//月折旧值	
				BigDecimal big=new BigDecimal(monthZj);
				double monthzj1=big.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
				double monthcz=fpje-monthZj-assetscz;//本月残值
				BigDecimal big1=new BigDecimal(monthcz);
				double monthcz1=big1.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
				Date date=new Date();
				SimpleDateFormat sdf=new SimpleDateFormat("yyyyMM");
				String day=sdf.format(date);//当前年月
				int days=Integer.parseInt(day)+1;
				int monthNum=Integer.parseInt(day)-startMonth+2;
				double zjall=monthZj*monthNum;//已折旧总值
				BigDecimal big2=new BigDecimal(zjall);
				double zjall1=big2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
				double assetsjz=fpje-monthzj1*monthNum;
//				System.out.println("残值率："+zjczlv);
//				System.out.println("年："+zjnx);
//				System.out.println("资产残值："+assetscz);
//				System.out.println("年折旧率："+yearZjlv);
//				System.out.println("月折旧率："+monthZjlv);
//				System.out.println("月折旧值："+monthzj1);
//				System.out.println("残值："+monthcz1);
//				System.out.println("资产净值:"+assetsjz);
//				System.out.println("当前年月："+days);
//				System.out.println("开始年月："+startMonth);
//				System.out.println("已折旧月数"+monthNum);
//				System.out.println("折旧总值"+zjall1);
				
				assetsRegister.setOperateType("USES");
				assetsRegister.setOperatePerson("admin");
				assetsRegister.setZjnow(assetsRegister.getZjnow());
				assetsRegister.setRecordTime(assetsRegister.getRecordTime());
				assetsRegister.setZjCurrentMonth(monthzj1);
				assetsRegister.setCzMinth(monthcz1);
				assetsRegister.setZcjz(assetsjz);
				assetsRegister.setZjnow(String.valueOf(days));
				assetsRegister.setZjmonth(monthNum);
				assetsRegister.setZjAll(zjall1);
				}
			}
		assetsLingYong.setAssetsRegisters(assets);
		this.assetsLingYongService.saveLingYongAndHitory(assetsLingYong);
		return SUCCESS;
	}
	
	@Action(value="saveUpdateAssetsHistoryRegisters",results={
			@Result(name="success",type="redirect",location="updateAssetsHistoryRegister"),
			@Result(name="error",type="chain",location="updateAssetsHistoryRegister")})
	public String saveUpdateAssetsHistoryRegisters(){
		this.saveUpdateAssetsHistoryRegister();
		return SUCCESS;
	}
	
	@Action(value="removeAssetsHistoryRegister",results={
			@Result(name="success",type="redirect",location="listAssetsHistoryRegister"),
			@Result(name="error",type="chain",location="listAssetsHistoryRegister")})
	public String removeAssetsHistoryRegister(){
		if(ids == null){
			this.setPrompt("请选择要删除的数据行！");
			return ERROR;
		}
//		this.assetsLingYongService.remove(assetsLingYong);
		this.assetsRegisterService.batchRemove(ids);
		return SUCCESS;
	}
	//资产台账
	@Action("listAssetsTaizhang")
	public String listAssetsTaizhang(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(AssetsRegister.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getAssetsRegisterService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	//当前资产流向
	@Action("listAssetsLiuXing")
	public String listAssetsLiuXing(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(AssetsRegister.class)
		.add(Restrictions.or(Restrictions.or(Restrictions.isNotNull("asssteRevert"), Restrictions.isNotNull("assetsLingYong")), Restrictions.isNotNull("assetsScrap")));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getAssetsRegisterService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("listAssetsLiuXiangHistory")
	public String listAssetsLiuXiangHistory(){
		this.listAssetsLiuXing();
		return SUCCESS;
	}
	//本月折旧
	@Action("listZheJiuMonth")
	public String listZhejiuMonth(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(AssetsRegister.class)
		.add(Restrictions.isNotNull("isZJ"));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getAssetsRegisterService().listByPage(criteria,pagination));
		return SUCCESS;
	}
	@Action("listZheJiuMonthHistory")
	public String listZheJiuMonthHistory(){
		this.listZhejiuMonth();
		return SUCCESS;
	}
}
